package com.etc.controller;


import com.etc.entity.Admin;
import com.etc.entity.AdminPojo;
import com.etc.entity.Goods;
import com.etc.service.AdminService;
import com.etc.service.GoodsService;
import com.etc.service.impl.AdminServiceImpl;
import com.etc.service.impl.GoodsServiceImpl;
import com.etc.util.PageData;
import com.etc.util.QueryResponseData;
import com.etc.util.ResponseData;
import org.springframework.web.bind.annotation.*;

@RestController
//通过后端来处理跨域问题
@CrossOrigin
@RequestMapping("api")
//@CrossOrigin(origins = "*",allowCredentials="true",allowedHeaders = "",methods = {})
public class AdminController {
    private AdminService service = new AdminServiceImpl();
//
//    @PostMapping("login")
//    public ResponseData login(@RequestParam("username") String adminname, @RequestParam("userpwd") String adminpwd) {
//        Admin admin = service.getAdmin(adminname, adminpwd);
//
//        ResponseData responseData = new ResponseData();
//        if (admin == null) {
//            responseData.setMsg("fail");
//        } else {
//            responseData.setObj(admin);
//        }
//        return responseData;
//
//    }

    @PostMapping("login")
    public ResponseData login(@RequestBody AdminPojo adminpojo) {

        Admin admin = service.getAdmin(adminpojo.getUsername(), adminpojo.getUserpwd());

        ResponseData responseData = new ResponseData();
        if (admin == null) {
            responseData.setMsg("fail");
        } else {
            responseData.setObj(admin);
        }
        return responseData;

    }
}
